//common field validator method
function isValidAlphaNumField(field, name) {
    var error = "";

    // check if field contains only letters and digits
    // and length between 5 and 25
    if (field.length < 5 || field.length > 26) {
        error = "\nLength must be between 5 and 25";
    }

    if (!field.match(/^[a-zA-Z0-9 \s]+$/)) {
        error += "\nMust contain letters and digits only including white spaces";
    }

    if (error != "") {
        alert("Invalid " + name + ":" + error);
        return false;
    }
    else return true;
}

function isValidName(field, name) {
    var error = "";

    // fname or lname cannot be blank
    if (field.length == 0) {
        error = "\nCannot be left blank";
    }

    if (!field.match(/^[a-zA-Z'-]+$/)) {
        error += "\nMust contain only letters A-Z including single quote and hyphen";
    }

    if (error != "") {
        alert("Invalid " + name + ":" + error);
        return false;
    }
    else return true;
}

function isValidUserId(id) {
    return id.match(/^[0-9]+$/);
}

function isValidPassword(pwd) {
    var error = "";

    // check if password contains only letters and digits
    // and length between 5 and 25
    if (pwd.length < 5 || pwd.length > 26) {
        error = "\nLength must be between 5 and 25";
    }

    if (!pwd.match(/^[a-zA-Z0-9]+$/)) {
        error += "\nMust contain letters and digits only";
    }

    if (error != "") {
        alert("Invalid password:" + error);
        return false;
    }
    else return true;
}

function showOrHide(id) {
    if(document.getElementById(id).style.display=='none')
        document.getElementById(id).style.display='block';
    else
        document.getElementById(id).style.display='none';
}